package fr.appliClient.server.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "VEHICULE")
public class Vehicle implements AbstractEntity<Long>, Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name = "immatriculation")
	private String registration;

	@Column(name = "date_achat")
	@Temporal(TemporalType.DATE)
	private Date purchaseDate;

	@ManyToOne
	@JoinColumn(name = "service_fk")
	private Service service;

	@ManyToOne
	@JoinColumn(name = "utilisateur_fk")
	private User user;

	@ManyToOne
	@JoinColumn(name = "responsable_fk")
	private User responsible;

	@ManyToOne
	@JoinColumn(name = "statut_fk")
	private Status status;

	@ManyToOne
	@JoinColumn(name = "famille_fk")
	private Family family;

	@ManyToOne
	@JoinColumn(name = "assurance_fk")
	private Insurance insurance;

	@OneToMany(mappedBy = "vehicle")
	private List<Consumption> consumptions;

	@OneToMany(mappedBy = "vehicle")
	private List<Maintenance> maintenances;

	public Vehicle() {

		this.consumptions = new ArrayList<Consumption>();
		this.maintenances = new ArrayList<Maintenance>();
	}

	public Service getService() {

		return this.service;
	}

	public void setService(Service service) {

		if (service != null) {
			this.service = service;
			if (!service.getVehicles().contains(this)) {
				service.getVehicles().add(this);
			}
		}
	}

	public User getUser() {

		return this.user;
	}

	public void setUser(User user) {

		if (user != null) {
			this.user = user;
			if (!user.getUserVehicles().contains(this)) {
				user.getUserVehicles().add(this);
			}
		}
	}

	public User getResponsible() {

		return this.responsible;
	}

	public void setResponsible(User responsible) {

		if (responsible != null) {
			this.responsible = responsible;
			if (!responsible.getResponsibleVehicles().contains(this)) {
				responsible.getResponsibleVehicles().add(this);
			}
		}
	}

	public Status getStatus() {

		return this.status;
	}

	public void setStatus(Status status) {

		if (status != null) {
			this.status = status;
			if (!status.getVehicles().contains(this)) {
				status.getVehicles().add(this);
			}
		}
	}

	public Family getFamily() {

		return this.family;
	}

	public void setFamily(Family family) {

		if (family != null) {
			this.family = family;
			if (!family.getVehicles().contains(this)) {
				family.getVehicles().add(this);
			}
		}
	}

	public Insurance getInsurance() {

		return this.insurance;
	}

	public void setInsurance(Insurance insurance) {

		if (insurance != null) {
			this.insurance = insurance;
			if (!insurance.getVehicles().contains(this)) {
				insurance.getVehicles().add(this);
			}
		}
	}

	public List<Consumption> getConsumptions() {

		return this.consumptions;
	}

	public void setConsumptions(List<Consumption> consumptions) {

		this.consumptions = consumptions;
	}

	public List<Maintenance> getMaintenances() {

		return this.maintenances;
	}

	public void setMaintenances(List<Maintenance> maintenances) {

		this.maintenances = maintenances;
	}

	public Date getPurchaseDate() {

		return this.purchaseDate;
	}

	public void setPurchaseDate(Date purchaseDate) {

		this.purchaseDate = purchaseDate;
	}

	/**
	 * @return the registration
	 */
	public String getRegistration() {

		return this.registration;
	}

	/**
	 * @param registration
	 *            the registration to set
	 */
	public void setRegistration(String registration) {

		this.registration = registration;
	}

	/**
	 * @return the id
	 */
	public Long getId() {

		return this.id;
	}

}
